/** ****************************公众来信********************************* */
$.ajaxSetup({
	cache : false
});
$(document).ready(function() {
	var timestamp = new Date().getTime();
	$("#verifyImage").attr("src", "/iac/random/code?" + timestamp);
	$("#verifyImage").load(function() {
		var timestamp = new Date().getTime();
		$.ajax({
			type : 'get',
			url : '/iac/random/getCode?' + timestamp,
			dataType : 'json',
			success : function(data) {
				$("#voicepath").val(data.path);
				// alert(data.path);
				// return data;
			}
		});
	});
	$("#verifyImage").click(function() {
		var timestamp = new Date().getTime();
		$("#verifyImage").attr("src", "/iac/random/code?" + timestamp);

	});
});
function changeImage() {
	var timestamp = new Date().getTime();
	$("#verifyImage").attr("src", "/iac/random/code?" + timestamp);
}
var hint = "如需继续提供错误提示信息！请选择【确定】; 若不提供！请选择【取消】";
var flag = true;
function submitPage() {
	var author = $.trim($("#author").val());
	var email = $.trim($("#email").val());
	var mobile = $.trim($("#mobile").val());
	var address = $.trim($("#address").val());
	var title = $.trim($("#title").val());
	var content = $.trim($("#content").val());
	var certicode = $.trim($("#certicode").val());
	var type = $("input[name='type']:checked").val();
	var show = $("input[name='show']:checked").val();
	if (author == "" || author == "请输入用户姓名") {
		if (flag == true) {
			alert("请输入用户姓名");
			show_confirm();
		}
		$("#author").focus();
		return false;
	}
	
	var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if (email == "" || email == "请输入邮箱" || reg.test(email) == false) {
		if (flag == true) {
			alert("请输入正确格式的电子邮件 例如example@163.com");
			show_confirm();
		}
		$("#email").focus();
		return false;
	}	
	
	
	reg = /^[1][358][0-9]{9}$/;
	if (mobile == "" || mobile == "请输入手机号码" || reg.test(mobile) == false) {
		if (flag == true) {
			alert("请输入正确手机号码 例如132XXXXXXXX");
			show_confirm();
		}
		$("#mobile").focus();
		return false;
	}	
	if (address == "" || address == "请输入通信地址") {
		if (flag == true) {
			alert("请输入通信地址");
			show_confirm();
		}
		$("#address").focus();
		return false;
	}	
	if (title == "" || title == "请输入主题") {
		if (flag == true) {
			alert("请输入主题");
			show_confirm();
		}
		$("#title").focus();
		return false;
	}	
	if (content == "" || content == "请输入内容(不超过1000个中文字符)") {
		if (flag == true) {
			alert("请输入内容");
			show_confirm();
		}
		$("#content").focus();
		return false;
	}	
	if (certicode == "") {
		if (flag == true) {
			alert("请输入验证码");
			show_confirm();
		}
		$("#certicode").focus();
		return false;
	}	
	$.ajax({
		type : 'post',
		url : '/iac/web/submitPage',
		data : {
			"author" : author,
			"email" : email,
			"mobile" : mobile,
			"address" : address,
			"type" : type,
			"show" : show,
			"title" : title,
			"content" : content,
			"certicode" : certicode
		},
		dataType : 'json',
		success : function(data) {
			if (data.notice == true) {
				alert(data.message);
				window.location.reload();
				return false;
			} else {
					alert(data.message);
					return false;
			}
		}
	});
	return false;
};


function show_confirm() {
	var r = confirm(hint);
	if (r == false) {
		flag = false;
	}
}


function authors() {
	author = $("#author").val();
	if (author == "请输入用户姓名") {
		$("#author").val("");
	}
}

function blurname() {
	author = $("#author").val();
	if ($.trim(author) == "") {
		$("#author").val("请输入用户姓名");
	}
}

function onemail() {
	email = $("#email").val();
	if (email == "请输入邮箱") {
		$("#email").val("");
	}
}

function bluremail() {
	email = $("#email").val();
	if ($.trim(email) == "") {
		$("#email").val("请输入邮箱");
	}
}
function onmobile() {
	mobile = $("#mobile").val();
	if (mobile == "请输入手机号码") {
		$("#mobile").val("");
	}
}

function blurmobile() {
	mobile = $("#mobile").val();
	if ($.trim(mobile) == "") {
		$("#mobile").val("请输入手机号码");
	}
}

function onaddress() {
	address = $("#address").val();
	if (address == "请输入通信地址") {
		$("#address").val("");
	}
}

function bluraddress() {
	address = $("#address").val();
	if ($.trim(address) == "") {
		$("#address").val("请输入通信地址");
	}
}

function ontitle() {
	title = $("#title").val();
	if (title == "请输入主题") {
		$("#title").val("");
	}
}
function blurtitle() {
	title = $("#title").val();
	if ($.trim(title) == "") {
		$("#title").val("请输入主题");
	}
}

function oncontent() {
	content = $("#content").val();
	if (content == "请输入内容(不超过1000个中文字符)") {
		$("#content").val("");
	}
}

function blurcontent() {
	content = $("#content").val();
	if ($.trim(content) == "") {
		$("#content").val("请输入内容(不超过1000个中文字符)");
	}
}

//function blurcerticode(){
//	certicode = $("#certicode").val();
//	if ($.trim(certicode) == "") {
//		$("#certicode").val("请输入验证码");
//	}
//}
